package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.pick.PreNoticeItemEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class PickWinningNoticeAdapter extends BaseRecycleAdapter<PreNoticeItemEntity> {

    private ImageView statusBid;
    private TextView endTime;
    private LinearLayout lineEndTime;
    private String time;

    public PickWinningNoticeAdapter(Context context, List<PreNoticeItemEntity> datas) {
        super(context, R.layout.item_pick_winning_notice, datas);
    }


    @Override
    public void convert(ItemViewHolder holder, PreNoticeItemEntity goodsInfoEntity3) {
        holder.setBinding(BR.viewModel, goodsInfoEntity3);


        endTime = holder.getItem().findViewById(R.id.text_end_time);
        statusBid = holder.getItem().findViewById(R.id.img_status_bid);
        lineEndTime = holder.getItem().findViewById(R.id.bid_end_time);

        if (goodsInfoEntity3.getShowEndTimeFlag() == 0) {
            lineEndTime.setVisibility(View.GONE);
        } else {
            lineEndTime.setVisibility(View.VISIBLE);
            long end = Long.valueOf(goodsInfoEntity3.getShowEndTime());
            long midTime = (end - System.currentTimeMillis()) / 1000;
            long dd = midTime / 86400;
            long hh = midTime % 86400 / 3600;            //转换小时
            long mm = midTime % 86400 % 3600 / 60;            //转换分钟

            if (dd > 0) {
                time =  dd + "天" + hh + "小时" + mm + "分钟";
            } else {
                if (hh > 0) {
                    time =  hh + "小时" + mm + "分钟";
                } else {
                    time =  mm + "分钟";
                }
            }
            endTime.setText(time);//*
        }

        switch (goodsInfoEntity3.getOrnumName()) {
            case "已废标":
                statusBid.setImageDrawable(context.getResources().getDrawable(R.mipmap.icn_yfb));
                statusBid.setVisibility(View.VISIBLE);
                break;
            case "已结束":
                statusBid.setImageDrawable(context.getResources().getDrawable(R.mipmap.icn_yjs));
                statusBid.setVisibility(View.VISIBLE);
                break;
            case "公示中":
                statusBid.setImageDrawable(context.getResources().getDrawable(R.mipmap.icon_gsz));
                statusBid.setVisibility(View.VISIBLE);
                break;
        }
    }

}
